package tw.asap.plus.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;

/**
 * Created by Yax on 15/7/22.
 */
public class DBHelper extends SQLiteOpenHelper {

    private static final String DB_NAME = "ASAP_CART_GOODS"; // 数据库名字
    private static final int VERSION = 100; // 版本号
    // 数据库表
    public static final String TABLE_GOODS = "CART";
    public static final String TABLE_SHOP = "SHOP";
    // 创建表结构
    public static final String goodsTable = "CREATE TABLE " + TABLE_GOODS + "(" + GoodsInfoColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + GoodsInfoColumns.SHOP_KEY + " TEXT,"
            + GoodsInfoColumns.GOODS_ID + " TEXT,"
            + GoodsInfoColumns.GOODS_COUNTS + " INTEGER)";

    public static final String shopTable = "CREATE TABLE " + TABLE_SHOP + "(" + GoodsInfoColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + GoodsInfoColumns.SHOP_GOODS_SUM + " INTEGER)";


    public DBHelper(Context context) {
        super(context, DB_NAME, null, VERSION);
    }


    public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, DB_NAME, factory, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        /***
         * 执行 SQ 语句
         */
        db.execSQL(goodsTable);
        db.execSQL(shopTable);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_GOODS);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_SHOP);
        onCreate(db);
    }


    /**
     * 用户
     *
     * @author notreami
     */
    public static final class GoodsInfoColumns implements BaseColumns {
        public static final String SHOP_KEY = "SHOP_KEY";
        public static final String GOODS_ID = "GOODS_ID";
        public static final String GOODS_COUNTS = "GOODS_COUNTS";
        public static final String SHOP_GOODS_SUM = "SHOP_GOODS_SUM";
    }

}
